﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace HighFantasy
{
    public enum CollisionType
    {
        None = 0,
        Object = 1,
        Enemy = 2

    }

    public class Collision
    {

        

        public CollisionType Type;
        public string state;
        public bool Value;



        public bool PlayerCollisionLeft(Player player, List<Object> objects, List<Enemy> enemies)
        {
            foreach (Object obj in objects){

                if (player.X + player.Width >= obj.localBounds.X && player.X <= obj.localBounds.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.localBounds.Y + obj.Height && player.Y + player.Height >= obj.localBounds.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Left";
                        return true;
                    }
                }
                else if (player.X + player.Width >= obj.localBounds.X && player.X <= obj.localBounds.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.localBounds.Y + obj.Height && player.Y + player.Height >= obj.localBounds.Y)
                    {


                        player.collision.Value = true;
                        player.collision.state = "Left";
                        return true;
                    }
                }
  
              else
              {
                  player.collision.Value = false;

              }


            }


            foreach (Enemy obj in enemies)
            {

                if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Left";
                        return true;
                    }
                }
                else if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {


                        player.collision.Value = true;
                        player.collision.state = "Left";
                        return true;
                    }
                }

                else
                {
                    player.collision.Value = false;

                }


            }
            return false;

           
        }

        public bool PlayerCollisionRight(Player player, List<Object> objects, List<Enemy> enemies)
        {
            foreach (Object obj in objects)
            {


                if (player.X <= obj.localBounds.X + obj.Width && player.X >= obj.localBounds.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.localBounds.Y + obj.Height && player.Y + player.Height >= obj.localBounds.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Right";
                        return true;
                    }
                }
                else if (player.X <= obj.localBounds.X + obj.Width && player.X >= obj.localBounds.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.localBounds.Y + obj.Height && player.Y + player.Height >= obj.localBounds.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Right";
                        return true;
                    }
                }

                else
                {
                    player.collision.Value = false;

                }


            }

            foreach (Enemy obj in enemies)
            {


                if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Right";
                        return true;
                    }
                }
                else if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true; 
                        player.collision.state = "Right";
                        return true;
                    }
                }

                else
                {
                    player.collision.Value = false;

                }


            }
            return false;


        }

        public bool PlayerCollisionTop(Player player, List<Object> objects, List<Enemy> enemies)
        {
            foreach (Object obj in objects)
            {

                if (player.Y + player.Height >= obj.localBounds.Y && player.Y <= obj.localBounds.Y && player.direction == 3)
                {

                    if (player.X <= obj.localBounds.X + obj.Width && player.X >= obj.localBounds.X)
                    {


                        player.collision.Value = true;
                        player.collision.state = "Top";
                        return true;

                    }
                }

                else
                    if (player.Y + player.Height >= obj.localBounds.Y && player.Y <= obj.localBounds.Y && player.direction == 4)
                    {
                        if (player.X <= obj.localBounds.X + obj.Width && player.X >= obj.localBounds.X)
                        {


                            player.collision.Value = true;
                            player.collision.state = "Top";
                            return true;
                        }

                    }

                    else
                    {

                        player.collision.Value = false;

                    }
            }

            foreach (Enemy obj in enemies)
            {

                if (player.Y + player.Height >= obj.Y && player.Y <= obj.Y && player.direction == 3)
                {

                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {


                        player.collision.Value = true;
                        player.collision.state = "Top";
                        return true;

                    }
                }

                else
                    if (player.Y + player.Height >= obj.Y && player.Y <= obj.Y && player.direction == 4)
                    {
                        if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                        {


                            player.collision.Value = true;
                            player.collision.state = "Top";
                            return true;
                        }

                    }

                    else
                    {

                        player.collision.Value = false;

                    }
            }
            return false;
        }

        public bool PlayerCollisionBottom(Player player, List<Object> objects, List<Enemy> enemies)
        {

            foreach (Object obj in objects)
            {

                if (player.Y <= obj.localBounds.Y + obj.Height && player.Y >= obj.localBounds.Y && player.direction == 4)
                {
                    if (player.X <= obj.localBounds.X + obj.Width && player.X >= obj.localBounds.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom";
                        return true;
                    }
                }
                else if (player.Y <= obj.localBounds.Y + obj.Height && player.Y >= obj.localBounds.Y && player.direction == 3)
                {
                    if (player.X <= obj.localBounds.X + obj.Width && player.X >= obj.localBounds.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }
            }

            foreach (Enemy obj in enemies)
            {

                if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 4)
                {
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom";
                        return true;
                    }
                }
                else if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 3)
                {
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }
            }
            return false;
        }

        public bool EnemyCollisionLeft(Player main, Enemy player, List<Object> objects, List<Enemy> enemies)
        {
            foreach (Object obj in objects)
            {

                if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Left1";
                        return true;
                    }
                }
                else if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {


                        player.collision.Value = true;
                        player.collision.state = "Left2";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }


            }


            foreach (Enemy obj in enemies)
            {

                if (obj != player){


                if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Left3";
                        return true;
                    }
                }
                else if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        
                        player.collision.Value = true;
                        player.collision.state = "Left4";

                        return true;
                    }
                }

                else
                {
                    player.collision.Value = false;

                }
                }

            }

            if (player.X + player.Width >= main.X && player.X <= main.X && player.direction == 2) //Left collision
            {

                if (player.Y <= main.Y + main.Height && player.Y + player.Height >= main.Y)
                {

                    player.collision.Value = true;
                    player.collision.state = "Left5";
                    return true;
                }
            }
            else if (player.X + player.Width >= main.X && player.X <= main.X && player.direction == 1) //Right collision
            {

                if (player.Y <= main.Y + main.Height && player.Y + player.Height >= main.Y)
                {


                    player.collision.Value = true;
                    player.collision.state = "Left6";

                    return true;
                }
            }

            else
            {
                player.collision.Value = false;

            }
            return false;


        }

        public bool NPCCollisionLeft(Player main, NPC player, List<Object> objects, List<Enemy> enemies)
        {
            foreach (Object obj in objects)
            {

                if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Left1";
                        return true;
                    }
                }
                else if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {


                        player.collision.Value = true;
                        player.collision.state = "Left2";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }


            }


            foreach (Enemy obj in enemies)
            {



                    if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 2) //Left collision
                    {

                        if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                        {

                            player.collision.Value = true;
                            player.collision.state = "Left3";
                            return true;
                        }
                    }
                    else if (player.X + player.Width >= obj.X && player.X <= obj.X && player.direction == 1) //Right collision
                    {

                        if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                        {


                            player.collision.Value = true;
                            player.collision.state = "Left4";

                            return true;
                        }
                    }

                    else
                    {
                        player.collision.Value = false;

                    }
                

            }

            if (player.X + player.Width >= main.X && player.X <= main.X && player.direction == 2) //Left collision
            {

                if (player.Y <= main.Y + main.Height && player.Y + player.Height >= main.Y)
                {

                    player.collision.Value = true;
                    player.collision.state = "Left5";
                    return true;
                }
            }
            else if (player.X + player.Width >= main.X && player.X <= main.X && player.direction == 1) //Right collision
            {

                if (player.Y <= main.Y + main.Height && player.Y + player.Height >= main.Y)
                {


                    player.collision.Value = true;
                    player.collision.state = "Left6";

                    return true;
                }
            }

            else
            {
                player.collision.Value = false;

            }
            return false;


        }

        public bool EnemyCollisionRight(Player main, Enemy player, List<Object> objects, List<Enemy> enemies)
        {
            
            foreach (Object obj in objects)
            {
                
                
                if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Right1";
                        return true;
                    }
                }
                else if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {
                        player.collision.Value = true;
                        player.collision.state = "Right2";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }


            }

            foreach (Enemy obj in enemies)
            {
                if (obj != player){

                if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Right3";
                        return true;
                    }
                }
                else if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Right4";
                        return true;
                    }
                }

                else
                {
                    player.collision.Value = false;

                }
                }

            }


            if (player.X <= main.X + main.Width && player.X >= main.X && player.direction == 1) //Right collision
            {

                if (player.Y <= main.Y + main.Height && player.Y + player.Height >= main.Y)
                {

                    player.collision.Value = true;
                    player.collision.state = "Right5";
                    return true;
                }
            }
            else if (player.X <= main.X + main.Width && player.X >= main.X && player.direction == 2) //Left collision
            {

                if (player.Y <= main.Y + main.Height && player.Y + player.Height >= main.Y)
                {

                    player.collision.Value = true;
                    player.collision.state = "Right6";
                    return true;
                }
            }

            else
            {
                player.collision.Value = false;

            }
            return false;


        }

        public bool NPCCollisionRight(Player main, NPC player, List<Object> objects, List<Enemy> enemies)
        {

            foreach (Object obj in objects)
            {


                if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 1) //Right collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Right1";
                        return true;
                    }
                }
                else if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 2) //Left collision
                {

                    if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                    {
                        player.collision.Value = true;
                        player.collision.state = "Right2";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }


            }

            foreach (Enemy obj in enemies)
            {
                
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 1) //Right collision
                    {

                        if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                        {

                            player.collision.Value = true;
                            player.collision.state = "Right3";
                            return true;
                        }
                    }
                    else if (player.X <= obj.X + obj.Width && player.X >= obj.X && player.direction == 2) //Left collision
                    {

                        if (player.Y <= obj.Y + obj.Height && player.Y + player.Height >= obj.Y)
                        {

                            player.collision.Value = true;
                            player.collision.state = "Right4";
                            return true;
                        }
                    }

                    else
                    {
                        player.collision.Value = false;

                    }
                

            }


            if (player.X <= main.X + main.Width && player.X >= main.X && player.direction == 1) //Right collision
            {

                if (player.Y <= main.Y + main.Height && player.Y + player.Height >= main.Y)
                {

                    player.collision.Value = true;
                    player.collision.state = "Right5";
                    return true;
                }
            }
            else if (player.X <= main.X + main.Width && player.X >= main.X && player.direction == 2) //Left collision
            {

                if (player.Y <= main.Y + main.Height && player.Y + player.Height >= main.Y)
                {

                    player.collision.Value = true;
                    player.collision.state = "Right6";
                    return true;
                }
            }

            else
            {
                player.collision.Value = false;

            }
            return false;


        }

        public bool EnemyCollisionTop(Player player, Enemy enemy, List<Object> objects, List<Enemy> enemies)
        {
            foreach (Object obj in objects)
            {

                if (enemy.Y + enemy.Height >= obj.Y && enemy.Y <= obj.Y && enemy.direction == 3)
                {

                    if (enemy.X <= obj.X + obj.Width && enemy.X >= obj.X)
                    {


                        enemy.collision.Value = true;
                        enemy.collision.state = "Top1";
                        return true;

                    }
                }

                else
                    if (enemy.Y + enemy.Height >= obj.Y && enemy.Y <= obj.Y && enemy.direction == 4)
                    {
                        if (enemy.X <= obj.X + obj.Width && enemy.X >= obj.X)
                        {


                            enemy.collision.Value = true;
                            enemy.collision.state = "Top2";
                            return true;
                        }

                    }

                    else
                    {

                        enemy.collision.Value = false;

                    }
            }

            foreach (Enemy obj in enemies)
            {
                if (obj != enemy)
                {

                    if (enemy.Y + enemy.Height >= obj.Y && enemy.Y <= obj.Y && enemy.direction == 3)
                {

                    if (enemy.X <= obj.X + obj.Width && enemy.X >= obj.X)
                    {


                        enemy.collision.Value = true;
                        enemy.collision.state = "Top3";
                        return true;

                    }
                }

                else
                        if (enemy.Y + enemy.Height >= obj.Y && enemy.Y <= obj.Y && enemy.direction == 4)
                    {
                        if (enemy.X <= obj.X + obj.Width && enemy.X >= obj.X)
                        {


                            enemy.collision.Value = true;
                            enemy.collision.state = "Top4";
                            return true;
                        }

                    }

                    else
                    {

                        enemy.collision.Value = false;

                    }
                }
            }



            if (enemy.Y + enemy.Height >= player.Y && enemy.Y <= player.Y && enemy.direction == 3)
            {

                if (enemy.X <= player.X + player.Width && enemy.X >= player.X)
                {


                    enemy.collision.Value = true;
                    enemy.collision.state = "Top5";
                    return true;

                }
            }

            else
                if (enemy.Y + enemy.Height >= player.Y && enemy.Y <= player.Y && enemy.direction == 4)
                {
                    if (enemy.X <= player.X + player.Width && enemy.X >= player.X)
                    {


                        enemy.collision.Value = true;
                        enemy.collision.state = "Top6";
                        return true;
                    }

                }

                else
                {

                    enemy.collision.Value = false;

                }
            return false;
        }

        public bool NPCCollisionTop(Player player, NPC enemy, List<Object> objects, List<Enemy> enemies)
        {
            foreach (Object obj in objects)
            {

                if (enemy.Y + enemy.Height >= obj.Y && enemy.Y <= obj.Y && enemy.direction == 3)
                {

                    if (enemy.X <= obj.X + obj.Width && enemy.X >= obj.X)
                    {


                        enemy.collision.Value = true;
                        enemy.collision.state = "Top1";
                        return true;

                    }
                }

                else
                    if (enemy.Y + enemy.Height >= obj.Y && enemy.Y <= obj.Y && enemy.direction == 4)
                    {
                        if (enemy.X <= obj.X + obj.Width && enemy.X >= obj.X)
                        {


                            enemy.collision.Value = true;
                            enemy.collision.state = "Top2";
                            return true;
                        }

                    }

                    else
                    {

                        enemy.collision.Value = false;

                    }
            }

            foreach (Enemy obj in enemies)
            {
                

                    if (enemy.Y + enemy.Height >= obj.Y && enemy.Y <= obj.Y && enemy.direction == 3)
                    {

                        if (enemy.X <= obj.X + obj.Width && enemy.X >= obj.X)
                        {


                            enemy.collision.Value = true;
                            enemy.collision.state = "Top3";
                            return true;

                        }
                    }

                    else
                        if (enemy.Y + enemy.Height >= obj.Y && enemy.Y <= obj.Y && enemy.direction == 4)
                        {
                            if (enemy.X <= obj.X + obj.Width && enemy.X >= obj.X)
                            {


                                enemy.collision.Value = true;
                                enemy.collision.state = "Top4";
                                return true;
                            }

                        }

                        else
                        {

                            enemy.collision.Value = false;

                        }
                
            }



            if (enemy.Y + enemy.Height >= player.Y && enemy.Y <= player.Y && enemy.direction == 3)
            {

                if (enemy.X <= player.X + player.Width && enemy.X >= player.X)
                {


                    enemy.collision.Value = true;
                    enemy.collision.state = "Top5";
                    return true;

                }
            }

            else
                if (enemy.Y + enemy.Height >= player.Y && enemy.Y <= player.Y && enemy.direction == 4)
                {
                    if (enemy.X <= player.X + player.Width && enemy.X >= player.X)
                    {


                        enemy.collision.Value = true;
                        enemy.collision.state = "Top6";
                        return true;
                    }

                }

                else
                {

                    enemy.collision.Value = false;

                }
            return false;
        }

        public bool EnemyCollisionBottom(Player main, Enemy player, List<Object> objects, List<Enemy> enemies)
        {

            foreach (Object obj in objects)
            {

                if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 4)
                {
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom1";
                        return true;
                    }
                }
                else if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 3)
                {
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom2";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }
            }

            foreach (Enemy obj in enemies)
            {
                if (obj != player){

                if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 4)
                {
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom3";
                        return true;
                    }
                }
                else if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 3)
                {
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom4";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }
               }
            }

            if (player.Y <= main.Y + main.Height && player.Y >= main.Y && player.direction == 4)
            {
                if (player.X <= main.X + main.Width && player.X >= main.X)
                {

                    player.collision.Value = true;
                    player.collision.state = "Bottom5";
                    return true;
                }
            }
            else if (player.Y <= main.Y + main.Height && player.Y >= main.Y && player.direction == 3)
            {
                if (player.X <= main.X + main.Width && player.X >= main.X)
                {

                    player.collision.Value = true;
                    player.collision.state = "Bottom6";
                    return true;
                }
            }

            else
            {

                player.collision.Value = false;
            }
            return false;
        }

        public bool NPCCollisionBottom(Player main, NPC player, List<Object> objects, List<Enemy> enemies)
        {

            foreach (Object obj in objects)
            {

                if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 4)
                {
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom1";
                        return true;
                    }
                }
                else if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 3)
                {
                    if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                    {

                        player.collision.Value = true;
                        player.collision.state = "Bottom2";
                        return true;
                    }
                }

                else
                {

                    player.collision.Value = false;
                }
            }

            foreach (Enemy obj in enemies)
            {
                

                    if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 4)
                    {
                        if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                        {

                            player.collision.Value = true;
                            player.collision.state = "Bottom3";
                            return true;
                        }
                    }
                    else if (player.Y <= obj.Y + obj.Height && player.Y >= obj.Y && player.direction == 3)
                    {
                        if (player.X <= obj.X + obj.Width && player.X >= obj.X)
                        {

                            player.collision.Value = true;
                            player.collision.state = "Bottom4";
                            return true;
                        }
                    }

                    else
                    {

                        player.collision.Value = false;
                    }
                
            }

            if (player.Y <= main.Y + main.Height && player.Y >= main.Y && player.direction == 4)
            {
                if (player.X <= main.X + main.Width && player.X >= main.X)
                {

                    player.collision.Value = true;
                    player.collision.state = "Bottom5";
                    return true;
                }
            }
            else if (player.Y <= main.Y + main.Height && player.Y >= main.Y && player.direction == 3)
            {
                if (player.X <= main.X + main.Width && player.X >= main.X)
                {

                    player.collision.Value = true;
                    player.collision.state = "Bottom6";
                    return true;
                }
            }

            else
            {

                player.collision.Value = false;
            }
            return false;
        }

    }
}
